home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -screenplay- / shareware / warpquake / warpquakesrc / in_amiga.c < prev    next >
C/C++ Source or Header  |  2000-02-29  |  4KB  |  200 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // in_null.c -- for systems without a mouse
  21.  
  22. #include <exec/exec.h>
  23. #include <intuition/intuition.h>
  24. #include <libraries/lowlevel.h>
  25. #include <powerup/ppcproto/lowlevel.h>
  26. #include <powerup/ppcproto/exec.h>
  27.  
  28. #include "quakedef.h"
  29.  
  30. cvar_t m_filter = {"m_filter", "1"};
  31.  
  32. qboolean using_mouse = false;
  33. qboolean using_joypad = false;
  34. short int last_mouse[2] = {0, 0};
  35. extern qboolean mousemove;
  36.  
  37. struct Library *LowLevelBase = NULL;
  38.  
  39. void IN_MouseMove (usercmd_t *cmd);
  40. void Init_Joypad (void);
  41. void Read_Joypad (void);
  42.  
  43. void Read_Joypad (void)
  44. {
  45.     ULONG joypos;
  46.  
  47.     joypos = ReadJoyPort(1);
  48.  
  49.     if (joypos & JPF_JOY_LEFT)
  50.         Key_Event (K_AUX1, true);
  51.     else
  52.         Key_Event (K_AUX1, false);
  53.  
  54.     if (joypos & JPF_JOY_RIGHT)
  55.         Key_Event (K_AUX2, true);
  56.     else
  57.         Key_Event (K_AUX2, false);
  58.  
  59.     if (joypos & JPF_JOY_UP)
  60.         Key_Event (K_AUX3, true);
  61.     else
  62.         Key_Event (K_AUX3, false);
  63.  
  64.     if (joypos & JPF_JOY_DOWN)
  65.         Key_Event (K_AUX4, true);
  66.     else
  67.         Key_Event (K_AUX4, false);
  68.  
  69.     if (joypos & JPF_BUTTON_RED)
  70.         Key_Event (K_AUX5, true);
  71.     else
  72.         Key_Event (K_AUX5, false);
  73.  
  74.     if (joypos & JPF_BUTTON_GREEN)
  75.         Key_Event (K_AUX6, true);
  76.     else
  77.         Key_Event (K_AUX6, false);
  78.  
  79.     if (joypos & JPF_BUTTON_YELLOW)
  80.         Key_Event (K_AUX7, true);
  81.     else
  82.         Key_Event (K_AUX7, false);
  83.  
  84.     if (joypos & JPF_BUTTON_BLUE)
  85.         Key_Event (K_AUX8, true);
  86.     else
  87.         Key_Event (K_AUX8, false);
  88.  
  89.     if (joypos & JPF_BUTTON_PLAY)
  90.         Key_Event (K_AUX9, true);
  91.     else
  92.         Key_Event (K_AUX9, false);
  93.  
  94.     if (joypos & JPF_BUTTON_FORWARD)
  95.         Key_Event (K_AUX10, true);
  96.     else
  97.         Key_Event (K_AUX10, false);
  98.  
  99.     if (joypos & JPF_BUTTON_REVERSE)
  100.         Key_Event (K_AUX11 ,true);
  101.     else
  102.         Key_Event (K_AUX11, false);
  103. }
  104.  
  105. void Init_Joypad (void)
  106. {
  107.     LowLevelBase = OpenLibrary ("lowlevel.library", 0);
  108.     if (LowLevelBase)
  109.     {
  110.         Con_Printf ("Joypad enabled\n");
  111.         using_joypad = true;
  112.     }
  113.     else
  114.         Con_Printf ("Can't open lowlevel.libary\n");
  115. }
  116.  
  117. void IN_Init (void)
  118. {
  119.   using_mouse = COM_CheckParm ("-mouse");
  120.   if (using_mouse)
  121.     Cvar_RegisterVariable (&m_filter);
  122.  
  123.     using_joypad = COM_CheckParm ("-joypad");
  124.     if (using_joypad)
  125.         Init_Joypad();
  126. }
  127.  
  128. void IN_Shutdown (void)
  129. {
  130.     if (LowLevelBase != NULL)
  131.     {
  132.         CloseLibrary (LowLevelBase);
  133.         LowLevelBase = NULL;
  134.     }
  135. }
  136.  
  137. void IN_Commands (void)
  138. {
  139.     if (using_joypad)
  140.         Read_Joypad();
  141. }
  142.  
  143. void IN_Move (usercmd_t *cmd)
  144. {
  145.     if (using_mouse)
  146.         IN_MouseMove (cmd);
  147. }
  148.  
  149. void IN_MouseMove(usercmd_t *cmd)
  150. {
  151.     short int mx, my;
  152.   double mouse_x, mouse_y;
  153.   static int old_mouse_x = 0, old_mouse_y = 0;
  154.  
  155.     if (mousemove == false)
  156.         return;
  157.  
  158.     mousemove = false;
  159.  
  160.     mx = (last_mouse[0] >> 1) << 3;
  161.   my = (last_mouse[1] >> 1) << 3;
  162.  
  163.     
  164.   if (m_filter.value) {
  165.     mouse_x = 0.5 * (mx + old_mouse_x);
  166.     mouse_y = 0.5 * (my + old_mouse_y);
  167.   } else {
  168.     mouse_x = (double)mx;
  169.     mouse_y = (double)my;
  170.   }
  171.  
  172.   mouse_x *= sensitivity.value;
  173.   mouse_y *= sensitivity.value;
  174.  
  175.   old_mouse_x = mx;
  176.   old_mouse_y = my;
  177.  
  178.   /* add mouse X/Y movement to cmd */
  179.   if ((in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1)))
  180.     cmd->sidemove += m_side.value * mouse_x;
  181.   else
  182.     cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  183.  
  184.   if (in_mlook.state & 1)
  185.     V_StopPitchDrift ();
  186.  
  187.   if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
  188.     cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  189.     if (cl.viewangles[PITCH] > 80)
  190.       cl.viewangles[PITCH] = 80;
  191.     if (cl.viewangles[PITCH] < -70)
  192.       cl.viewangles[PITCH] = -70;
  193.   } else {
  194.     if ((in_strafe.state & 1) && noclip_anglehack)
  195.       cmd->upmove -= m_forward.value * mouse_y;
  196.     else
  197.       cmd->forwardmove -= m_forward.value * mouse_y;
  198.   }
  199. }
  200.